<?php

namespace ctrl;

use model\video_cate;
use libs\view;

class videocate extends base
{
	private static $themeDir = P_ROOT."/app/index/view/default/video/";//内容列表模板路径
	private static $M;
	public static function Init()
	{
		parent::init();
		self::$M = new video_cate;
	}
	public static function index()
	{
		if (isset($_GET['list_json'])) {
			$jsonlist = array();
			$jsonlist['code'] = 0;
			$jsonlist['msg'] = '';
			$jsonlist['data'] = self::$M->SelectData();
			exit(json_encode($jsonlist));
		}else{
			view::display();
		}
	}

	public static function add()
	{
		if (isset($_GET['view'])) {
			view::assign('templist',GetFileFolderList(static::$themeDir,0,"*.html"));
			view::assign('info', null);
			view::assign('title', "添加视频栏目");
			view::display("post");
		} else {
			$result = self::$M->insertData();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}

	public static function edit()
	{
		if (isset($_GET['view'])) {
			$info = self::$M->FindData();
			view::assign('info', $info);
			view::assign('templist',GetFileFolderList(static::$themeDir,0,"*.html"));
			view::assign('title', "编辑视频栏目");
			view::display("post");
		} elseif (isset($_GET['sortedit'])) {
			$result = self::$M->updateSort();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		} else {
			$result = self::$M->updateData();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}


	public static function del()
	{
		if (self::$M->deleteOneData())
			Response(array('status' => 1, 'info' => '删除成功'));
		else
			Response(array('status' => 0, 'info' => '该视频栏目下有内容，拒绝删除！'));
	}
}
